﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
using System.Diagnostics;

namespace TomVanGaever.BCS.Parser
{
    public partial class ParserForm : Form
    {
        string m_title = "BCS Parser Settings {0}/{1}:";

        private List<BCSUserControl> m_BCScontrols = new List<BCSUserControl>();
        public List<BCSUserControl> BCScontrols
        {
            get { return m_BCScontrols; }
            set { m_BCScontrols = value; }
        }

        private static ParserForm m_currentActiveForm;

        public static Button NextButton
        {
            get { return ParserForm.m_currentActiveForm.btnNext; }
            set { ParserForm.m_currentActiveForm.btnNext = value; }
        }
        public static Button PreviousButton
        {
            get { return ParserForm.m_currentActiveForm.btnPrevious; }
            set { ParserForm.m_currentActiveForm.btnPrevious = value; }
        }
        public static Button BCSCancelButton
        { 
            get { return ParserForm.m_currentActiveForm.btnCancel; }
            set { ParserForm.m_currentActiveForm.btnCancel = value; } 
        }
    
        public ParserForm()
        {
            InitializeComponent();
            ParserForm.m_currentActiveForm = this;
        }

        //public void LoadClasses(IEnumerable<Type> types)
        //{
        //    string typemember = "FullName";
        //    m_types = types;

        //    IEnumerable<Type> entities =  m_types.Where(t => t.GetProperties().Count() != 0).ToList();
        //    lstClasses.DisplayMember = typemember;
        //    lstClasses.DataSource = entities;

        //    lstServiceClasses.DisplayMember = typemember;
        //    lstServiceClasses.DataSource = m_types.ToList();
        //}

        //public Type SelectedType {
        //    get { return lstClasses.SelectedItem as Type; }
        //}

        //public Type SelectedTypeService {
        //    get { return lstServiceClasses.SelectedItem as Type; }
        //}

        //public PropertyInfo SelectedIdentifier
        //{
        //    get { return lstIdentifierProperties.SelectedItem as PropertyInfo; }
        //}

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Process.Start("http://tomvangaever.be");
        }

        private void ParserForm_Load(object sender, EventArgs e)
        {
            ShowControl(this.BCScontrols.First());
        }

        private void ShowControl(BCSUserControl c){
            c.Dock = DockStyle.Fill;
            pnlHolder.Controls.Clear();
            pnlHolder.Controls.Add(c);
            int index = this.BCScontrols.IndexOf((BCSUserControl)c);
            this.Text = string.Format(m_title, index+1, this.BCScontrols.Count);
			lblTitle.Text = string.Format(m_title, index + 1, this.BCScontrols.Count);
			lbldescription.Text = c.TitleText;
        }

        private void btnNext_Click(object sender, EventArgs e)
        {
            int index = this.BCScontrols.IndexOf((BCSUserControl)pnlHolder.Controls[0]);
            int next = index + 1;
            BCSUserControl c = this.BCScontrols[next];
            ShowControl(c);
            if (this.BCScontrols.Count-1 == next) {
                ParserForm.NextButton.Enabled = false;
            }
            if (next > 0)
            {
                ParserForm.PreviousButton.Enabled = true;
            }
			
        }

        private void btnPrevious_Click(object sender, EventArgs e)
        {
            int index = this.BCScontrols.IndexOf((BCSUserControl)pnlHolder.Controls[0]);
            int next = index - 1;
            BCSUserControl c = this.BCScontrols[next];
            ShowControl(c);
            if (next <= 0)
            {
                ParserForm.PreviousButton.Enabled = false;
                ParserForm.NextButton.Enabled = true;
            }
            else {
                ParserForm.PreviousButton.Enabled = true;
                ParserForm.NextButton.Enabled = true;
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            Close();
        }
        
    }
}
